<template>
  <div class="smart-home-container">
    <!-- 顶部房间信息栏 -->
    <div class="room-header">
      <h1 class="room-title">客厅</h1>
      <div class="room-status">
        <div class="status-item">
          <i class="fas fa-temperature-high"></i>
          <span>26°C</span>
        </div>
        <div class="status-item">
          <i class="fas fa-tint"></i>
          <span>45%</span>
        </div>
      </div>
    </div>

    <!-- 设备状态快速预览 -->
    <div class="device-overview">
      <div class="device-card" :class="{ active: devices.light.status }">
        <div class="device-icon">
          <i class="fas fa-lightbulb"></i>
        </div>
        <div class="device-info">
          <h3>照明系统</h3>
          <p v-if="devices.light.status">{{ devices.light.brightness }}% 亮度</p>
          <p v-else>已关闭</p>
        </div>
      </div>

      <div class="device-card" :class="{ active: devices.ac.status }">
        <div class="device-icon">
          <i class="fas fa-snowflake"></i>
        </div>
        <div class="device-info">
          <h3>空调系统</h3>
          <p v-if="devices.ac.status">{{ devices.ac.temperature }}°C | {{ devices.ac.mode }}</p>
          <p v-else>已关闭</p>
        </div>
      </div>

      <div class="device-card" :class="{ active: devices.curtain.status }">
        <div class="device-icon">
          <i class="fas fa-border-all"></i>
        </div>
        <div class="device-info">
          <h3>窗帘控制</h3>
          <p>{{ devices.curtain.openness }}% 开合度</p>
        </div>
      </div>

      <div class="device-card" :class="{ active: devices.appliance.status }">
        <div class="device-icon">
          <i class="fas fa-plug"></i>
        </div>
        <div class="device-info">
          <h3>电器监控</h3>
          <p v-if="devices.appliance.status">运行中</p>
          <p v-else>待机</p>
        </div>
      </div>
    </div>

    <!-- 设备控制面板 -->
    <div class="control-panel">
      <div class="switch-buttons">
        <button class="control-button" :class="{ active: devices.light.status }" @click="toggleDevice('light')">
          <i class="fas fa-lightbulb"></i>
        </button>
        <button class="control-button" :class="{ active: devices.ac.status }" @click="toggleDevice('ac')">
          <i class="fas fa-snowflake"></i>
        </button>
        <button class="control-button" :class="{ active: devices.appliance.status }" @click="toggleDevice('appliance')">
          <i class="fas fa-plug"></i>
        </button>
      </div>

      <div class="slider-controls">
        <div class="slider-group">
          <label>亮度调节</label>
          <input type="range" min="0" max="100" v-model="devices.light.brightness" :disabled="!devices.light.status">
          <span>{{ devices.light.brightness }}%</span>
        </div>

        <div class="slider-group">
          <label>温度调节</label>
          <input type="range" min="16" max="30" v-model="devices.ac.temperature" :disabled="!devices.ac.status">
          <span>{{ devices.ac.temperature }}°C</span>
        </div>

        <div class="slider-group">
          <label>窗帘开合</label>
          <input type="range" min="0" max="100" v-model="devices.curtain.openness">
          <span>{{ devices.curtain.openness }}%</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const devices = ref({
  light: {
    status: true,
    brightness: 80
  },
  ac: {
    status: false,
    temperature: 24,
    mode: "制冷"
  },
  curtain: {
    status: true,
    openness: 50
  },
  appliance: {
    status: true
  }
});

const toggleDevice = (device: string) => {
  devices.value[device].status = !devices.value[device].status;
};
</script>

<style scoped>
.smart-home-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background-color: #f8f9fa;
  min-height: 100vh;
  box-sizing: border-box;
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 20px;
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.room-title {
  font-size: 24px;
  color: #333;
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.room-status {
  display: flex;
  gap: 20px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  color: #555;
}

.device-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.device-card {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.device-card.active {
  border-left: 4px solid #4CAF50;
}

.device-card:not(.active) {
  opacity: 0.8;
}

.device-icon {
  width: 50px;
  height: 50px;
  background-color: #e9f5ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #2196F3;
  font-size: 24px;
}

.device-info h3 {
  margin: 0 0 5px 0;
  font-size: 18px;
  color: #333;
}

.device-info p {
  margin: 0;
  font-size: 14px;
  color: #666;
}

.control-panel {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.switch-buttons {
  display: flex;
  justify-content: space-around;
  margin-bottom: 30px;
}

.control-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background-color: #f0f0f0;
  color: #666;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-button.active {
  background-color: #4CAF50;
  color: white;
  transform: scale(1.05);
}

.control-button:active {
  transform: scale(0.95);
}

.slider-controls {
  display: grid;
  gap: 20px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-group label {
  font-size: 14px;
  color: #555;
}

.slider-group input[type="range"] {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #e0e0e0;
  outline: none;
  -webkit-appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #4CAF50;
  cursor: pointer;
}

.slider-group input[type="range"]:disabled {
  opacity: 0.5;
}

.slider-group input[type="range"]:disabled::-webkit-slider-thumb {
  background: #999;
}

.slider-group span {
  font-size: 14px;
  color: #333;
  text-align: right;
}

.fa-temperature-high,
.fa-tint,
.fa-lightbulb,
.fa-snowflake,
.fa-border-all,
.fa-plug {
  font-size: inherit;
}
</style>
